package com.yn.club.auth.domain.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yn.club.common.util.PageReq;
import com.yn.club.common.util.PageResp;
import java.io.Serializable;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import com.yn.club.auth.domain.entity.AuthUserRoleDO;
import com.yn.club.auth.infra.basic.entity.AuthUserRole;
import com.yn.club.auth.domain.service.AuthUserRoleDomainService;
import com.yn.club.auth.infra.basic.service.AuthUserRoleService;
import com.yn.club.auth.domain.convert.AuthUserRoleDomainConverter;


/**
 * 用户角色表(AuthUserRole)表服务接口实现类
 *
 * @author YN
 * @since 2025-01-22 10:07:43
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class AuthUserRoleDomainServiceImpl implements AuthUserRoleDomainService {

  private final AuthUserRoleService authUserRoleService;
  private final AuthUserRoleDomainConverter authUserRoleDomainConverter;


  /**
   * 分页
   */
  @Override
  public PageResp<AuthUserRoleDO> page(PageReq pageReq, AuthUserRoleDO query){
    QueryWrapper<AuthUserRole> querywrapper = new QueryWrapper<AuthUserRole>()
        .eq(query.getId() != null, "id", query.getId())
        .orderByDesc("id");
        
    Page<AuthUserRole> page = authUserRoleService.page(
      new Page<>(pageReq.getPageIndex(),pageReq.getPageSize()),querywrapper);
    List<AuthUserRole> list = page.getRecords();  
    return PageResp.of(page,authUserRoleDomainConverter.convertEntityToDo(list));
  }

  /**
   * 新增数据
   */
  @Override
  public Boolean insert(AuthUserRoleDO obj){
    AuthUserRole authUserRole = authUserRoleDomainConverter.convertDoToEntity(obj);
    return authUserRoleService.save(authUserRole);
  };


  /**
   * 更新数据
   */
  @Override
  public Boolean updateById(AuthUserRoleDO obj){
    AuthUserRole authUserRole = authUserRoleDomainConverter.convertDoToEntity(obj);
    return authUserRoleService.updateById(authUserRole);
  };

  /**
   * 批量删除
   */
  @Override
  public Boolean delete(List<Integer> ids){
    return authUserRoleService.removeByIds(ids);
  };

  /**
   * 根据id查找
   */
  @Override
  public AuthUserRoleDO getById(Serializable id){
    AuthUserRole authUserRole = authUserRoleService.getById(id);
    return  authUserRoleDomainConverter.convertEntityToDo(authUserRole);
  };


}

